package com.zztl.infiniteBand.adapter

import android.text.TextUtils
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.model.InviteIncomeBean
import com.zztl.infiniteBand.util.DataFormatUtil
import com.zztl.infiniteBand.util.DateUtils
import com.zztl.infiniteBand.util.GlideCircleTransform
import java.util.*


/**
 * @desc
 * @auth ${user}
 * @time 2018/5/18  10:12
 */
class InviteIncomeAdapter(layoutResId: Int, data: List<InviteIncomeBean.DataBean>?) : BaseQuickAdapter<InviteIncomeBean.DataBean, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: InviteIncomeBean.DataBean) {
        val incomeDate = item.incomeDate
        val date = DateUtils.formatNoYearAndSecondsTime(Date(incomeDate))
        val split = date.split("-")
        helper.setGone(R.id.rl_status, if (item.type == "1") true else false)
                .setText(R.id.tv_status, if (item.loginState == "1") "已实名" else "未实名")
                .setText(R.id.tv_invite_person, item.nickName)
                .setText(R.id.tv_award, if (item.loginState == "1") DataFormatUtil.converTxtPoint4(item.money.toDouble()) else "0")
                .setText(R.id.tv_award_time, split[0] + "\n" + split[1])
        val ivIcon = helper.itemView.findViewById<ImageView>(R.id.iv_header)
        if (!TextUtils.isEmpty(item.photo)) {
            Glide.with(ivIcon.context)
                    .load(item.photo)
                    .apply(RequestOptions().placeholder(R.mipmap.ic_defaultphoto).transform(GlideCircleTransform(ivIcon.context)))
                    .into(ivIcon)
        }
    }
}
